<?php
/**
 * Created by PhpStorm.
 * User: Mo
 * Date: 15-6-8
 * Time: 下午10:58
 */

$mem = new Memcache;
$mem->connect('localhost', 11211);
$key = "dataCache";
$rows = $mem->get($key);

if (empty($rows)) {
    include_once("../connect.php");
    $stmt = $pdo->prepare("select * from pic8 where toid=? order by ptime ");
    $stmt->execute(array(3));
    $rows = array();
    while ($row = $stmt->fetch()) {
        $rows[] = $row;
    }
    $mem->set($key, $rows, MEMCACHE_COMPRESSED, 10);
    $times = intval($mem->increment($key . 'Times') or $mem->set($key . 'Times', 1));
    echo "这是第 $times 次访问从数据库取数据放入内存中！<br>";
}

if (is_array($rows) && count($rows)) {
    foreach ($rows as $row) {
        echo <<<HTML
<li>
    <div class="txtitle"><a href="$row[pic_href].html">$row[pic_dm]</a></div>
    <div class="tximg"><a href="$row[pic_href].html"><img src="/shop/$row[pic_url]" alt="$row[pic_dm]" /></a></div>
</li>
HTML;
    }
}




